import { internation, getDictDatasAll, cardformInitData, queryCardFormColumnsWithUserId, searchcolumdisplay } from '@/api/api'

export default {
    async created() {
        await this._internation()
        await this._getDictDatasAll()
        this._cardformInitData()
        this._queryCardFormColumnsWithUserId()
        this._cardformInitColumn()
    },
    methods: {
        _cardformInitData(type) {
            const params = {
                'order': 'asc',
                'offset': (this.pager.offset - 1) * this.pager.limit,
                'limit': this.pager.limit || 20,
                'containerParam': {},
                'paramsMap': {},
                'requestParam': this.requestParam,
                'filter': this.filterData,
                'userIds': null,
                'formId': this.formId,
                'isView': null,
                'heightGrade': []
            }
            this.listLoading = true
            cardformInitData(params)
                .then((res) => {
                    console.log(res)
                    this.totalData = res.total
                    if (type === 'loadMore') {
                        this.list = this.list.concat(res.rows)
                        this.pager.offset += 1
                    } else {
                        this.list = res.rows
                    }
                    this.listLoading = false
                })
        },
        // 查询字段权限
        _queryCardFormColumnsWithUserId() {
            queryCardFormColumnsWithUserId(this.formId)
                .then((res) => {
                    console.log(res)
                    if (res) {
                        const temp = {}
                        res.forEach((item) => {
                            temp[item.formEntityTablename.replace(/_/g, '') + '_' + item.formFieldTablename.toUpperCase()] = item.formColumnType
                        })
                        console.log(temp)
                        this.fieldValid = temp
                        // this.settings.columns = []
                    }
                })
        },
        _cardformInitColumn() {
            searchcolumdisplay(this.formId)
                .then(res => {
                    console.log(res)
                    if (res.rcode === '0000') {
                        this.columnDate = res.data
                    } else {
                        this.$notify({
                            message: res.desc,
                            type: 'error',
                            duration: 2000
                        })
                    }
                })
        },
        // 国际化
        _internation() {
            internation(this.formId)
                .then(res => {
                    console.log(res)
                    const local = res.data
                    console.log(local)
                    this.$i18n.mergeLocaleMessage('en', local.en)
                    this.$i18n.mergeLocaleMessage('zh', local['zh-CN'])
                })
        },
        _getDictDatasAll() {
            getDictDatasAll(this.formId)
                .then(res => {
                    console.log(res)
                    this.dictValues = res
                })
        }
    }
}
